/**
 * Copyright (c) Software Institude of PKU
 * All rights reserved. 
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 */
package edu.pku.sei.modeler.model.uml.Ports;
// imports:
import org.w3c.dom.Element;

import edu.pku.sei.gefcommon.descriptor.annotation.MethodProperty;
import edu.pku.sei.modeler.model.common.MetaTypedList;
import edu.pku.sei.modeler.model.uml.BasicComponents.Component;
import edu.pku.sei.modeler.model.uml.BehaviorStateMachines.Transition;
import edu.pku.sei.modeler.model.uml.Interfaces.Interface;
import edu.pku.sei.modeler.model.uml.InternalStructures.Connector;
import edu.pku.sei.modeler.model.uml.Kernel.AggregationKind;
import edu.pku.sei.modeler.model.uml.Kernel.NamedElement;
import edu.pku.sei.modeler.model.uml.Kernel.UMLElement;
import edu.pku.sei.modeler.model.uml.Kernel.VisibilityKind;
import edu.pku.sei.modeler.model.uml.ProtocalStateMachines.ProtocalStateMachine;
import edu.pku.sei.modeler.model.uml.StructuredClasses.StructuredClass;
import edu.pku.sei.modeler.model.xml.XMLUtility;
import edu.pku.sei.modeler.uml.modelHelper.ModelPackage;


/**
 * @generated
 *
 */
public class Port extends NamedElement implements IPort {
	// attributes
	
	protected boolean isBehavior;
	
	protected boolean isService;
	
	
	
	
	// references
	
	protected MetaTypedList required;
	
	protected MetaTypedList provided;
	
	protected MetaTypedList redefinedPort;
	
	protected MetaTypedList protocol;
	
	//especially for the storation of delegation
	protected MetaTypedList incoming;
	protected MetaTypedList outgoing;
	
	protected StructuredClass structuredClass;
	
	
	// getters & setters for attributes
	
	public StructuredClass getStructuredClass() {
		return structuredClass;
	}
	public void setStructuredClass(StructuredClass structuredClass) {
		this.structuredClass = structuredClass;
	}
	@MethodProperty(
			id = "PORT_ISBEHAVIOR",
			catalog = "Model",
			name = ModelPackage.PORT_ISBEHAVIOR,
			setter = "setisBehavior"
			)
	
	public boolean getIsBehavior() {
		return isBehavior;
	}
	public void setIsBehavior(boolean newIsBehavior) {
		boolean oldisBehavior = isBehavior;
		isBehavior = newIsBehavior;
		firePropertyChange(ModelPackage.PORT_ISBEHAVIOR, oldisBehavior, newIsBehavior);
	}
	
	@MethodProperty(
			id = "PORT_ISSERVICE",
			catalog = "Model",
			name = ModelPackage.PORT_ISSERVICE,
			setter = "setisService"
			)
	
	public boolean getIsService() {
		return isService;
	}
	public void setIsService(boolean newIsService) {
		boolean oldisService = isService;
		isService = newIsService;
		firePropertyChange(ModelPackage.PORT_ISSERVICE, oldisService, newIsService);
	}
	
	// getters for references
	
	public MetaTypedList getRequired() {
		if(required == null) {
			required = new MetaTypedList(Interface.class, this, ModelPackage.PORT_REQUIRED);
		}
		return required;
	}
	
	public MetaTypedList getProvided() {
		if(provided == null) {
			provided = new MetaTypedList(Interface.class, this, ModelPackage.PORT_PROVIDED);
		}
		return provided;
	}
	
	public MetaTypedList getRedefinedPort() {
		if(redefinedPort == null) {
			redefinedPort = new MetaTypedList(Port.class, this, ModelPackage.PORT_REDEFINEDPORT);
		}
		return redefinedPort;
	}
	
	public MetaTypedList getProtocol() {
		if(protocol == null) {
			protocol = new MetaTypedList(ProtocalStateMachine.class, this, ModelPackage.PORT_PROTOCOL);
		}
		return protocol;
	}
	
	public MetaTypedList getOutgoing() {
		if(outgoing == null) {
			outgoing = new MetaTypedList(Connector.class, this, ModelPackage.VERTEX_OUTGOING);
		}
		return outgoing;
	}
	
	public MetaTypedList getIncoming() {
		if(incoming == null) {
			incoming = new MetaTypedList(Connector.class, this, ModelPackage.VERTEX_INCOMING);
		}
		return incoming;
	}
	
	// save & load
	public void serialize(Element root) {
		super.serialize(root);
		// attributes
		
		XMLUtility.xmlInstance.serializeAttribute(root, ModelPackage.PORT_ISBEHAVIOR, isBehavior);
		
		XMLUtility.xmlInstance.serializeAttribute(root, ModelPackage.PORT_ISSERVICE, isService);
		
		// references
		
		XMLUtility.xmlInstance.serializeNodesNotContain(root, ModelPackage.PORT_REQUIRED, required);		
		
		XMLUtility.xmlInstance.serializeNodesNotContain(root, ModelPackage.PORT_PROVIDED, provided);		
		
		XMLUtility.xmlInstance.serializeNodes(root, ModelPackage.VERTEX_OUTGOING, outgoing);
		
		XMLUtility.xmlInstance.serializeNodesNotContain(root, ModelPackage.VERTEX_INCOMING, incoming);
		
		XMLUtility.xmlInstance.serializeNodesNotContain(root, ModelPackage.PORT_REDEFINEDPORT, redefinedPort);		
		
		XMLUtility.xmlInstance.serializeNodesNotContain(root, ModelPackage.PORT_PROTOCOL, protocol);	
		
		XMLUtility.xmlInstance.serializeNodeNotContain(root, ModelPackage.PORT_STRUCTUREDCLASS, this.structuredClass);
	}
	
	public void deSerialize(Element root) {
		super.deSerialize(root);
		// attributes
		
		isBehavior = XMLUtility.xmlInstance.deSerializeBoolean(root, ModelPackage.PORT_ISBEHAVIOR);
		
		isService = XMLUtility.xmlInstance.deSerializeBoolean(root, ModelPackage.PORT_ISSERVICE);
		
		// references
		
		this.getRequired().addAll(XMLUtility.xmlInstance.deSerializeNodesNotContain(root, ModelPackage.PORT_REQUIRED, this));
		
		this.getProvided().addAll(XMLUtility.xmlInstance.deSerializeNodesNotContain(root, ModelPackage.PORT_PROVIDED, this));
		
		this.getOutgoing().addAll(XMLUtility.xmlInstance.deSerializeNodes(root, ModelPackage.VERTEX_OUTGOING));
		
		this.getIncoming().addAll(XMLUtility.xmlInstance.deSerializeNodesNotContain(root, ModelPackage.VERTEX_INCOMING, this));
		
		this.getRedefinedPort().addAll(XMLUtility.xmlInstance.deSerializeNodesNotContain(root, ModelPackage.PORT_REDEFINEDPORT, this));
		
		this.getProtocol().addAll(XMLUtility.xmlInstance.deSerializeNodesNotContain(root, ModelPackage.PORT_PROTOCOL, this));
		
		this.structuredClass = (StructuredClass) XMLUtility.xmlInstance.deSerializeNodeNotContain(root, ModelPackage.PORT_STRUCTUREDCLASS, this);
		
	}
	
	public void dynamicSet(String featureID, Object value) {
		if(featureID == null || "".equals(featureID)) {
			return;
		}
		// attributes
		
		// references
		
		else if(ModelPackage.PORT_REQUIRED.equals(featureID)) {
			getRequired().add(value);
		}
		
		else if(ModelPackage.PORT_PROVIDED.equals(featureID)) {
			getProvided().add(value);
		}
		
		else if(ModelPackage.PORT_REDEFINEDPORT.equals(featureID)) {
			getRedefinedPort().add(value);
		}
		
		else if(ModelPackage.PORT_PROTOCOL.equals(featureID)) {
			getProtocol().add(value);
		}
		else if (ModelPackage.PORT_STRUCTUREDCLASS.equals(featureID)) {
			this.structuredClass = (Component) value;
		}
		
		else
			super.dynamicSet(featureID, value);
	}
	
	public AggregationKind getAggregation() {
		// TODO Auto-generated method stub
		return null;
	}
	
	public MetaTypedList getAssociation() {
		// TODO Auto-generated method stub
		return null;
	}
	
	public String getDefaultLiteral() {
		// TODO Auto-generated method stub
		return null;
	}
	
	public MetaTypedList getDefaultValue() {
		// TODO Auto-generated method stub
		return null;
	}
	
	public boolean getIsComposite() {
		// TODO Auto-generated method stub
		return false;
	}
	
	public boolean getIsDerived() {
		// TODO Auto-generated method stub
		return false;
	}
	
	public boolean getIsDerivedUnion() {
		// TODO Auto-generated method stub
		return false;
	}
	
	public MetaTypedList getOpposite() {
		// TODO Auto-generated method stub
		return null;
	}
	
	public MetaTypedList getRedefinedProperty() {
		// TODO Auto-generated method stub
		return null;
	}
	
	public MetaTypedList getSubsettedProperty() {
		// TODO Auto-generated method stub
		return null;
	}
	
	public void setAggregation(AggregationKind newAggregation) {
		// TODO Auto-generated method stub
		
	}
	
	public void setDefaultLiteral(String newDefaultLiteral) {
		// TODO Auto-generated method stub
		
	}
	
	public void setIsComposite(boolean newIsComposite) {
		// TODO Auto-generated method stub
		
	}
	
	public void setIsDerived(boolean newIsDerived) {
		// TODO Auto-generated method stub
		
	}
	
	public void setIsDerivedUnion(boolean newIsDerivedUnion) {
		// TODO Auto-generated method stub
		
	}
	
	public boolean getIsReadOnly() {
		// TODO Auto-generated method stub
		return false;
	}
	
	public void setIsReadOnly(boolean newIsReadOnly) {
		// TODO Auto-generated method stub
		
	}
	
	public boolean getIsStatic() {
		// TODO Auto-generated method stub
		return false;
	}
	
	public void setIsStatic(boolean newIsStatic) {
		// TODO Auto-generated method stub
		
	}
	
	public boolean getIsLeaf() {
		// TODO Auto-generated method stub
		return false;
	}
	
	public MetaTypedList getRedefinedElement() {
		// TODO Auto-generated method stub
		return null;
	}
	
	public MetaTypedList getRedefinitionContext() {
		// TODO Auto-generated method stub
		return null;
	}
	
	public void setIsLeaf(boolean newIsLeaf) {
		// TODO Auto-generated method stub
		
	}
	
	public boolean getIsOrdered() {
		// TODO Auto-generated method stub
		return false;
	}
	
	public boolean getIsUnique() {
		// TODO Auto-generated method stub
		return false;
	}
	
	public int getLower() {
		// TODO Auto-generated method stub
		return 0;
	}
	
	public MetaTypedList getLowerValue() {
		// TODO Auto-generated method stub
		return null;
	}
	
	public int getUpper() {
		// TODO Auto-generated method stub
		return 0;
	}
	
	public MetaTypedList getUpperValue() {
		// TODO Auto-generated method stub
		return null;
	}
	
	public void setIsOrdered(boolean newIsOrdered) {
		// TODO Auto-generated method stub
		
	}
	
	public void setIsUnique(boolean newIsUnique) {
		// TODO Auto-generated method stub
		
	}
	
	public void setLower(int newLower) {
		// TODO Auto-generated method stub
		
	}
	
	public void setUpper(int newUpper) {
		// TODO Auto-generated method stub
		
	}
	
	public MetaTypedList getType() {
		// TODO Auto-generated method stub
		return null;
	}
	
	public MetaTypedList getEnd() {
		// TODO Auto-generated method stub
		return null;
	}
	
	public MetaTypedList getDeployedElement() {
		// TODO Auto-generated method stub
		return null;
	}
	
	public MetaTypedList getDeployment() {
		// TODO Auto-generated method stub
		return null;
	}
}
 
 
 
 
 